package com.huadao.cart_ccs.experiment.changeLiquidPlan;

import com.huadao.cart_ccs.Event.LiquidLoopPlanEvent;
import com.huadao.cart_ccs.common.ProjectManager;
import com.huadao.cart_ccs.greendao.GreenDaoManager;
import com.huadao.cart_ccs.greendao.entity.LiquidLoopPlan;
import com.huadao.cart_ccs.greendao.gen.LiquidLoopPlanDao;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

public class ChangeLiquidPlanListPresenter extends IChangeLiquidPlanListContract.IChangeLiquidPlanListPresenter {

    private LiquidLoopPlanDao liquidLoopPlanDao;
    public ChangeLiquidPlanListPresenter(IChangeLiquidPlanListContract.IChangeLiquidPlanListView baseView) {
        attachView(baseView);
        liquidLoopPlanDao=GreenDaoManager.getInstance().getSession().getLiquidLoopPlanDao();
    }

    @Override
    void getPlanList() {
        List<LiquidLoopPlan> liquidLoopPlans=liquidLoopPlanDao.queryBuilder().where(LiquidLoopPlanDao.Properties.ProjectId.eq(ProjectManager.getInstance().getProjectId())).list();
        baseView.onGetPlanList(liquidLoopPlans);
    }

    @Override
    void addPlan(LiquidLoopPlan plan) {
        liquidLoopPlanDao.insert(plan);
        EventBus.getDefault().post(new LiquidLoopPlanEvent(plan,LiquidLoopPlanEvent.evetn_add));
    }

    @Override
    public void deletePlan(LiquidLoopPlan liquidLoopPlan) {
        liquidLoopPlanDao.delete(liquidLoopPlan);
        EventBus.getDefault().post(new LiquidLoopPlanEvent(liquidLoopPlan,LiquidLoopPlanEvent.evetn_delete));
    }
}
